package video.background.Utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;
import video.background.Dao.MessageDao;
import video.background.Dao.MsgUserDao;
import video.background.Dao.TeamDao;
import video.background.Model.Message;
import video.background.Model.MsgUser;
import video.background.Model.Team;

import javax.annotation.PostConstruct;

@Component
public class MessageUtils {
    @Autowired
    private MessageDao messageDao;
    @Autowired
    private MsgUserDao msgUserDao;
    @Autowired
    private TeamDao teamDao;
    public static MessageUtils messageUtils;
    @PostConstruct
    public void init(){
        messageUtils = this;
    }

    public static void sendMessage(Long userId,String userName,int type,Long groupId) {
        Team team = messageUtils.teamDao.selectById(groupId);
        String title = "";
        String content = "";
        if (type == 0) {
            title = "创建团队成功";
            content = "恭喜您，创建团队" + team.getGroupName() + "成功，可以对您的团队进行操作啦！";
        } else if (type == 1) {
            title = "删除团队成功";
            content = "恭喜您，删除团队" + team.getGroupName() + "成功，您的团队已经被删除啦！";
        } else if (type == 2) {
            title = "上传声纹成功";
            content = "恭喜您，上传声纹到团队" + team.getGroupName() + "成功，您的声纹已经被上传到团队文件啦！";
        } else if (type == 3) {
            title = "修改声纹成功";
            content = "恭喜您，修改团队" + team.getGroupName() + "声纹成功，您的声纹已经被修改到团队文件啦！";
        } else if (type == 4) {
            title = "修改团队信息成功";
            content = "恭喜您，修改团队信息" + team.getGroupName() + "成功，快去看看新的团队吧！";
        } else if (type == 5) {
            title = "修改密码成功";
            content = "恭喜您，修改密码成功，请记住新密码并不要被别人知道噢~";
        } else if (type == 6) {
            title = "加入团队成功";
            content = "恭喜您，成功加入团队" + team.getGroupName() + "，快去团队看看吧！";
        } else if (type == 7) {
            title = "退出团队成功";
            content = "恭喜您，成功退出团队" + team.getGroupName() + "，快去其他团队看看吧！";
        } else if (type == 8) {
            title = "被踢出成功";
            content = " 很抱歉通知您，已经被团队" + team.getGroupName() + "踢出，请加入其他团队吧！";
        } else if (type == 9) {
            title = "权限修改成功";
            content = "您在团队" + team.getGroupName() + "内的权限已经被修改，请去团队查看吧！";
        }
        Message message = new Message(null,title,'1',content,userId,userName);
        messageUtils.messageDao.insert(message);
        MsgUser msgUser = new MsgUser(null,message.getMessageId(),userId,DateTimeUtils.localDateTimeAndSecondToString(),0);
        messageUtils.msgUserDao.insert(msgUser);
    }
}
